package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.unit.DataUnit;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysArtistApply;
import com.ruoyi.system.service.ISysArtistApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 申请管理Controller
 * 
 * @author Yaphets
 * @date 2024-07-04
 */

@Api(tags = "申请管理")
@RestController
@RequestMapping("/system/apply")
public class SysArtistApplyController extends BaseController
{
    @Autowired
    private ISysArtistApplyService sysArtistApplyService;

    /**
     * 查询申请管理列表
     */

    @ApiOperation("查询申请管理列表")
    @ApiResponse(code = 200, message = "查询申请管理列表", response = TableDataInfo.class)
//    @PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysArtistApply sysArtistApply)
    {
        startPage();
        List<SysArtistApply> list = sysArtistApplyService.selectSysArtistApplyList(sysArtistApply);
        return getDataTable(list);
    }

    /**
     * 查询人员是否有信息查看权限
     */

    @ApiOperation("查询人员是否有信息查看权限")
    @ApiResponse(code = 200, message = "查询人员是否有信息查看权限", response = AjaxResult.class)
//    @PreAuthorize("@ss.hasPermi('system:apply:list')")
    @PostMapping("/checkRight")
    public AjaxResult checkRight(@RequestBody SysArtistApply sysArtistApply)
    {
        boolean right = sysArtistApplyService.checkRight(sysArtistApply);
        return success().put("right", right);
    }

    /**
     * 导出申请管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:export')")
    @Log(title = "申请管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysArtistApply sysArtistApply)
    {
        List<SysArtistApply> list = sysArtistApplyService.selectSysArtistApplyList(sysArtistApply);
        ExcelUtil<SysArtistApply> util = new ExcelUtil<SysArtistApply>(SysArtistApply.class);
        util.exportExcel(response, list, "申请管理数据");
    }

    /**
     * 获取申请管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysArtistApplyService.selectSysArtistApplyById(id));
    }

    /**
     * 新增申请管理
     */

    @ApiOperation("新增申请管理")
    @ApiResponse(code = 200, message = "success", response = AjaxResult.class)
//    @PreAuthorize("@ss.hasPermi('system:apply:add')")
    @Log(title = "申请管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysArtistApply sysArtistApply)
    {
        sysArtistApply.setUserId(SecurityUtils.getUserId());
        sysArtistApply.setUserName(SecurityUtils.getUserNickName());
        sysArtistApply.setApplyDate(DateUtils.getNowDate());
        return toAjax(sysArtistApplyService.insertSysArtistApply(sysArtistApply));
    }

    /**
     * 申请审批
     */

    @ApiOperation("申请审批")
    @ApiResponse(code = 200, message = "success", response = AjaxResult.class)
//    @PreAuthorize("@ss.hasPermi('system:apply:edit')")
    @Log(title = "申请管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysArtistApply sysArtistApply)
    {
        return toAjax(sysArtistApplyService.updateSysArtistApply(sysArtistApply));
    }

    /**
     * 删除申请管理
     */
//    @PreAuthorize("@ss.hasPermi('system:apply:remove')")
    @Log(title = "申请管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysArtistApplyService.deleteSysArtistApplyByIds(ids));
    }
}
